<?php
class Cms_View_Helper_SubStrText
{
    public $view;

    public function substrtext($value, $length,$addTail=true)
    {
    	if($addTail == true)
			$tail = '...';
		else 
			$tail = '';
	    $text = strip_tags(trim($value));
	    
	  
		
		$txtl = strlen($text);
		if($txtl > $length) {
			for($i=1;$text[$length-$i]!=" ";$i++) {
				if($i == $length) {
					return substr($text,0,$length) . $tail;
				}
			}
			$text = substr($text,0,$length-$i+1) . $tail;
		}
		echo $text;
    }

    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }
}